<template xmlns:th="http://www.w3.org/1999/xhtml">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="检查单号" prop="checkId
">
        <el-input
          v-model="queryParams.checkId"
          placeholder="请输入检查单号"
          clearable
          size="small"
          @keyup.enter.native="getIDList"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getIDList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="checkList"
      row-key="rricd"
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      width="100%"
      border
    >
      <el-table-column prop="rrcid" label="检查单号" ></el-table-column>
      <el-table-column prop="rrname" label="检查项目" ></el-table-column>
      <el-table-column prop="rcname" label="患者姓名" ></el-table-column>
      <el-table-column prop="rrcstatus" label="检查状态" :formatter="statusFormat" ></el-table-column>
      <el-table-column prop="rrcresult" label="检查结果" ></el-table-column>
      <el-table-column prop="createtime" label="创建时间" ></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="findResult(scope.row)"
            v-hasPermi="['system:dept:add']"
          >检查结果</el-button>
        </template>
      </el-table-column>

    </el-table>

    <!-- 检查结果对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>

          <span>检查结果</span><span v-text="form.rrcresult"></span>
          <br>

          <el-image
            style="width: 100px; height: 100px"
            :src="form.url"
            :fit="fit"></el-image>



        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCheck,listCheckId,showImage } from "@/api/check/edit";
import Treeselect from "@riophae/vue-treeselect";
import { getToken } from "@/utils/auth";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Dept",
  components: { Treeselect },
  data() {
    return {
      previewUrl : "",
      checkName :[],
      radio1: this.grouped,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
        // 检查单数据
        resultCheckList: [],
      // 检查单数据
      checkList: [],
      // 部门树选项
      deptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        checkId:undefined,
        deptName: undefined,
        status: 2
      },
        // 上传检查结果
        upload: {
            // 设置上传的请求头部
            headers: { Authorization: "Bearer " + getToken() },
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + "/check/upload"
        },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        parentId: [
          { required: true, message: "上级部门不能为空", trigger: "blur" }
        ],
        deptName: [
          { required: true, message: "部门名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "显示排序不能为空", trigger: "blur" }
        ],
        email: [
          {
            type: "email",
            message: "'请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("check_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
      uploaded(response){
          this.form.rrcpicture = response.msg;
          console.log(this.form.rrcpicture);
      },
    /** 查询表单列表 */
    getList() {
      this.loading = true;
        listCheck(this.queryParams.status).then(response => {
        this.checkList = this.handleTree(response.data);
        this.loading = false;
      });
    },
    getIDList(){
        this.loading = true;
        listCheckId(this.queryParams.checkId).then(response => {
            this.checkList = this.handleTree(response.data);
            this.loading = false;
        });
    },


    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children
      };
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.rrcstatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
          rrcid: 0,
          rcname: undefined,
          rrname: undefined,
          rrcstatus: 1,
          rrcresult: '王中王',
          rrcpicture:undefined,
          rcremark:undefined,
          createby: undefined,
          createtime: undefined,
          updateby: undefined,
          updatetime: undefined,
          remark:undefined,
          url:undefined,

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getIDList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
      /** 结果照片回显操作 */
      findResult(row) {
          this.reset();
          this.open = true;
          const rrcid = row.rrcid;
          listCheckId(rrcid).then(response => {
              this.form.rrcresult = response.data[0].rrcresult;
              this.form.rrcpicture = response.data[0].rrcpicture;
              this.form.url="http://192.168.58.233:8080/check/imageName?imageName="+encodeURIComponent(response.data[0].rrcpicture);
          });
      },
  }
};
</script>
